package com.codemasters.programa;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;

import com.codemasters.datos.BaseDeDatos;
import com.codemasters.datos.Cliente;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.SQLException;

public class frmRegistrarCliente extends JFrame {
	
	

	private JPanel contentPane;
	private JTextField txtNombreCliente;
	private JTextField txtApellidoCliente;

	
	
	
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					frmRegistrarCliente frame = new frmRegistrarCliente();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public frmRegistrarCliente() 
	{
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JButton btnRegistrarCliente = new JButton("Registrar");
		
		JLabel lblNombre = new JLabel("Nombre:");
		
		JLabel lblApellido = new JLabel("Apellido:");
		
		txtNombreCliente = new JTextField();
		txtNombreCliente.setColumns(10);
		
		txtApellidoCliente = new JTextField();
		txtApellidoCliente.setColumns(10);
		
		
		
		JLabel lblRegistroDeClientes = new JLabel("Registro De Clientes");
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		
	
		
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////BOTON REGISTRAR EL CLIENTE//////////////////////////////////////////////////////////////////		
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
		
		btnRegistrarCliente.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0)
			{
					
			 try {
				 
					//Objeto tipo cliente con los datos del cliente
					Cliente cliente = new Cliente(txtNombreCliente.getText(), txtApellidoCliente.getText());
					
					//Registrando en la base de datos el cliente
					BaseDeDatos.registrarCliente(cliente);
					
					
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
		

		
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////		
		
		
		
		
		
		
		
		
		
		
		
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(127)
							.addComponent(btnRegistrarCliente))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(62)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(lblApellido)
									.addGap(18)
									.addComponent(txtApellidoCliente))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(lblNombre)
									.addGap(18)
									.addComponent(txtNombreCliente, GroupLayout.PREFERRED_SIZE, 160, GroupLayout.PREFERRED_SIZE))))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addGap(133)
							.addComponent(lblRegistroDeClientes)))
					.addContainerGap(143, Short.MAX_VALUE))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblRegistroDeClientes)
					.addGap(34)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNombre)
						.addComponent(txtNombreCliente, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblApellido)
						.addComponent(txtApellidoCliente, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 72, Short.MAX_VALUE)
					.addComponent(btnRegistrarCliente)
					.addGap(52))
		);
		contentPane.setLayout(gl_contentPane);
	}

}
